package top.buyibuyi.course.dao;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import top.buyibuyi.course.pojo.Admin;
import top.buyibuyi.course.pojo.ChooseCourse;
import top.buyibuyi.course.pojo.Course;
import top.buyibuyi.course.pojo.StuSchose;

import java.util.List;

@Mapper
public interface SelectStuChoseDao {

    /**
     * 条件分页查询，通过姓名和学号查询学生选课表中的信息
     * @param startPage
     * @param limit
     * @param sname
     * @param stuid
     * @return
     */
    @Select("<script>"
            + "select * from stuchose where 1=1 "
            +"<if test=\"sname != null and sname != ''\">"
            +" and sname LIKE concat('%', #{sname}, '%')"
            +"</if>"
            +"<if test=\"stuid != null and stuid != ''\">"
            +" and stuid LIKE concat('%', #{stuid}, '%')"
            +"</if>"
            +"and id limit #{startPage},#{limit}"
            +"</script>")
    @Results({
            @Result(column = "chooseid",property = "chooseid"),
            @Result(column = "chooseid",property = "chooseCourse", one = @One(select = "top.buyibuyi.course.dao.SelectStuChoseDao.selectChooseByChooseid",fetchType = FetchType.LAZY))
    })
    List<StuSchose> selectStuChose(@Param("startPage") int startPage, @Param("limit") int limit, @Param("sname") String sname, @Param("stuid") String stuid);


    /**
     * 通过学生选课表中的chooseid查询选课表中的信息
     * @param chooseid
     * @return
     */
    @Results({
            @Result(column = "courseid",property = "courseid"),
            @Result(column = "courseid",property = "course", one = @One(select = "top.buyibuyi.course.dao.SelectStuChoseDao.selectCourseByCourseId",fetchType = FetchType.LAZY))
    })
    @Select("select * from choosecourse where id = #{chooseid}")
    ChooseCourse selectChooseByChooseid(int chooseid);

    /**
     * 通过选课表中的courseid查询课程信息
     * @param courseid
     * @return
     */
    @Select("select * from course where id = #{courseid}")
    Course selectCourseByCourseId(int courseid);



    /**
     * 分页查询中总记录条数的查询语句
     * @param schose
     * @return
     */

    @Select("<script>"
            + "select count(*) as 'totalpage' from stuchose where 1=1 "
            +"<if test=\"sname != null and sname != ''\">"
            +" and sname LIKE concat('%', #{sname}, '%')"
            +"</if>"
            +"<if test=\"stuid != null and stuid != ''\">"
            +" and stuid LIKE concat('%', #{stuid}, '%')"
            +"</if>"
            +"</script>")
    int selectCount(StuSchose schose);


    @Select("<script>"
            + "select * from stuchose where college = #{college}"
            +"<if test=\"sname != null and sname != ''\">"
            +" and sname LIKE concat('%', #{sname}, '%')"
            +"</if>"
            +"<if test=\"stuid != null and stuid != ''\">"
            +" and stuid LIKE concat('%', #{stuid}, '%')"
            +"</if>"
            +"and id limit #{startPage},#{limit}"
            +"</script>")
    List<StuSchose> selectCollgeeStuChose(@Param("startPage") int startPage, @Param("limit") int limit,
                                          @Param("sname") String sname, @Param("stuid") String stuid,@Param("college") String college);
}
